#include<iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

class String{
  private:
  string str;
  public:
     void inputString(const string& s) {
        str = s;
    }
      void ch_delete(char ch){
      string result;
        for (char c : str) {
            if (c!= ch) {
                result += c;
            }
        }
        str = result;
      }
    bool operator<(const String& other) const {
      return str < other.str;
    }

    
    void outputString() const {
        cout << str << endl;
    } 
                     
};


int main() {
    char ch;
    cin >> ch;
    vector<String> strings;
    string input;
    while (true) {
        cin >> input;
        if (input == "@") {
            break;
        }
        String sh;
        sh.inputString(input);
        sh.ch_delete(ch);
        strings.push_back(sh);
    }
    sort(strings.begin(), strings.end());
    for (auto it = strings.rbegin(); it!= strings.rend(); ++it) {
        it->outputString();
    }
    return 0;
}